<template>
	<view class="">
		<view class="form-body">
			<u-form labelPosition="left" :model="formData" :rules="rules" ref="form" labelWidth="140" errorType="toast">
				<u-form-item label="部门名称" prop="organizationName" borderBottom>
					<u-input v-model="formData.organizationName" border="none" placeholder="请输入"></u-input>
				</u-form-item>
				<u-form-item label="部门负责人" prop="manager" borderBottom>
					<u-input v-model="formData.manager" border="none" placeholder="请输入"></u-input>
				</u-form-item>
				<u-form-item label="部门电话" prop="mobile" borderBottom>
					<u-input v-model="formData.mobile" border="none" placeholder="请输入"></u-input>
				</u-form-item>
				<u-form-item label="总部产品利润比例" prop="countryProfitGoods" borderBottom>
					<u-input v-model="formData.countryProfitGoods" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="总部营业额比例" prop="countryProfitIncome" borderBottom>
					<u-input v-model="formData.countryProfitIncome" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="省级产品利润比例" prop="provinceProfitGoods" borderBottom>
					<u-input v-model="formData.provinceProfitGoods" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="省级营业额比例" prop="provinceProfitIncome" borderBottom>
					<u-input v-model="formData.provinceProfitIncome" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="市级产品利润比例" prop="cityProfitGoods" borderBottom>
					<u-input v-model="formData.cityProfitGoods" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="市级营业额比例" prop="cityProfitIncome" borderBottom>
					<u-input v-model="formData.cityProfitIncome" type="number" border="none" placeholder="请输入"></u-input>
					<text slot="right">%</text>
				</u-form-item>
			</u-form>
		</view>
		<view class="bottom-button">
			<u-button type="primary" size="large" color="#e54d42" text="确定" @click="onSubmit"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isEdit: false,
				localData: [],
				formData: {
					organizationName: '',
					manager:'',
					mobile:''
				},
				rules: {
					organizationName: [{
						required: true,
						message: '请输入部门名称',
						trigger: ['change', 'blur']
					}],
					manager: [{
						required: true,
						message: '请输入负责人',
						trigger: ['change', 'blur']
					}]
				},
			}
		},
		onLoad(option) {
			// 省市区数据树生成
			// this.localData = this.get_city_tree()
			let that = this
			if (option.id) {
				uni.setNavigationBarTitle({
					title: '编辑部门资料',
				})
				this.isEdit = true
				this.getEdit(option.id)
			} else {
				uni.setNavigationBarTitle({
					title: '新增部门'
				})
				this.isEdit = false
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			// 省市区数据树生成
			get_city_tree() {
				let res = []
				if (cityRows.length) {
					// 递归生成
					res = this.handleTree(cityRows)
				}
				return res
			},
			getEdit(id) {
				let that = this
				this.$reqJsonPost('OrganizationGetEdit', {
					id: id
				}).then(res => {
					this.formData = res.data.model
					// this.fileList.push({ url:res.data.imageUrl })

				})
			},
			onSubmit() {
				this.$refs.form.validate().then(res => {
					if (this.isEdit) {
						this.$reqJsonPost('OrganizationDoEdit', this.formData).then(res => {
							uni.navigateBack()
						})
					} else {
						this.$reqJsonPost('OrganizationDoCreate', this.formData).then(res => {
							uni.navigateBack()
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.form-body {
		padding: 20rpx;
		background-color: #fff;
	}
</style>